// 0-1 背包问题


#include <stdio.h>
#include <stdlib.h>

int main() {
    int total;      // 充电桩
    scanf("%d", &total);
    int *eachPower = (int *)malloc(sizeof(int *) * total);
    for(int i = 0; i < total; i++) {
        scanf("%d", &eachPower[i]);
    }
    int maxPower;
    scanf("%d", &maxPower);

    int **dp = (int **)malloc(sizeof(int *) * total);
    for(int i = 0; i < total; i++) {
        dp[i] = malloc(sizeof(int) * (maxPower + 1));
    }

    for(int i = 0; i < total; i++) {
        dp[i][0] = 0;
    }
    for(int j = 0; j < maxPower + 1; j++) {
        if (eachPower[0] <= j) {
            dp[0][j] = eachPower[0];
        } else {
            dp[0][j] = 0;
        }
    }

    for(int i = 1; i < total; i++) {
        for(int j = 1; j < maxPower + 1; j++) {
            if (eachPower[i] > j) dp[i][j] = dp[i - 1][j];
            else {
                int a = dp[i - 1][j];
                int b = dp[i - 1][j - eachPower[i]] + eachPower[i];
                dp[i][j] = a > b ? a : b;
            }
        }
    }
    printf("%d\n", dp[total - 1][maxPower]);
    free(eachPower);
    for(int i = 0; i < total; i++) {
        free(dp[i]);
    }
    free(dp);
    return 0;
}